package mn.idax.exchange.otc.util;

import mn.idax.exchange.otc.constant.ReferenceExchageConstant;

import java.math.BigDecimal;

/**
 * 百分率计算
 *
 * @author .jension
 * @time 2018.12.05 11:22
 */
public class PercentageUtils {

    private static final BigDecimal PERCENTAGE = new BigDecimal("100");

    /**
     * 计算正负 N% BigDecimal
     *
     * @param number
     * @param rate      百分率数值
     * @return
     */
    public static BigDecimal calculation(BigDecimal number, BigDecimal rate) {
        return number.multiply(PERCENTAGE.add(rate).divide(PERCENTAGE)).setScale(ReferenceExchageConstant.DECIMAL, BigDecimal.ROUND_DOWN);
    }

    public static void main(String[] args) {
        System.out.println(calculation(new BigDecimal("1000"),  new BigDecimal("30")).toString());
        System.out.println(calculation(new BigDecimal("1000"),  new BigDecimal("-30")).toString());
    }
}
